<style>
.layui-form-pane .layui-form-label{width:auto;}
.layui-form-item{margin-bottom: 0px;}
.layui-table-cell{padding:1px 2px;text-align:center;font-size:13px;line-height:19px;}

th span{white-space:normal;}
.finance tbody tr td {
    padding: 3px 0px !important;
    font-size: 12px !important;
}
.notprofit{color:red;}
#totaldata_tag a{color:#0033CC;
text-decoration:underline;}
</style>
<div class="fixed-bar">
	<form class="layui-form layui-form-pane fixed-bar-form" action="{:url()}" method="get" id="hisi-table-search">
	<div class="layui-form-item">
		<div class="layui-inline">
			<label class="layui-form-label">所属工厂</label>
			<div class="layui-input-inline">
				{:Form::select('factory_id', '666', $factoryKV, '', '')}
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">尾部完成日期</label>
			<div class="layui-input-inline">
				<input type="text" name="over_date_range" readonly="" value="{$overtime_range}" id="over_date_range" lay-verify="" placeholder="选择完成日期" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<button type="submit" id="seacher" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
            <button type="button" class="layui-btn layui-btn-primary hisi-export" style="display:none">导出</button>
		</div>
	</div>
	</form>
</div>
<table id="dataTable" lay-filter='dataTable'></table>

{include file="system@block/layui" /}
<script type="text/html" id="createTimeTpl">
{{# if(d.create_time > 0){ }} 
	<span title="{{ layui.util.toDateString(d.create_time * 1000,'yyyy-MM-dd HH:mm')}}">{{ layui.util.toDateString(d.create_time * 1000,'MM-dd') }} </span>
{{# } }}
</script>
<script type="text/html" id="caichuangTimeTpl">
{{# if(d.create_time > 0){ }} 
	<span title="{{ layui.util.toDateString(d.caichuang_over_time * 1000,'yyyy-MM-dd HH:mm')}}">{{ layui.util.toDateString(d.caichuang_over_time * 1000,'MM-dd') }} </span>
{{# } }}
</script>
<script type="text/html" id="clientStatusTpl">
    {{# if(d.status == 99){ }}<span class="layui-badge">{{ d.delete_text }}</span><br> {{# } }}
	{{ clientStatus[d.client_status].replace(/生产中/, "") }}
</script>
<script type="text/html" id="buttonTpl">
<a href="{:url('statisticsDetail')}?over_date_range={{d.over_date_range}}&factory_id={{ d.ofactory_id}}&sizefactory_id={{ d.factory_id}}" title="成品订单明细列表" class="hisi-iframe layui-btn layui-btn-xs layui-btn-normal" target="_blank"  hisi-data="{width: '100%', height: '100%'}">订单明细</a>
</script>

<script type="text/html" id="countOrderTpl">
{{ d.tail_order_count}}/{{d.finish_order_count}}
</script>
<script type="text/html" id="toolbar">
	<span style="float:left" id="totaldata_tag">
		<span id="TotalPer">正品率： 次品率</span> 
		&nbsp;&nbsp;&nbsp;快捷筛选：<a onclick="searchdate('{$searchdate[1]} ~ {$searchdate[2]}')" href="#">当月</a>&nbsp;&nbsp;   
		<a onclick="searchdate('{$searchdate[3]} ~ {$searchdate[4]}')" href="#">上月</a>&nbsp;&nbsp; 
		<a onclick="searchdate('{$searchdate[5]} ~ {$searchdate[6]}')" href="#">近三月</a>&nbsp;&nbsp; 
		<a onclick="searchdate('{$searchdate[7]} ~ {$searchdate[8]}')" href="#">近半年</a>&nbsp;&nbsp; 
	</span>
	<span style="float:right">&nbsp;&nbsp;备注说明->  <strong>正品率</strong>：(入仓+入库-出库)/(裁数+补裁片)， <strong>次品率</strong>：次品数/(裁数+补裁片)</span>
	<div style="clear:both"><strong>列表结果：</strong>所有统计订单的结果，<strong>统计订单</strong>：已尾完并所有子单已入仓或手工加入统计的订单，<strong>总可出库数</strong>：总下单数的30%，<strong>报废率</strong>：1-(MES入仓+没收件数+米莫入库数+次品数)/(裁床件数+补片数)</div>
</script>

<script type="text/javascript">
	var factoryKV = {:json_encode($factoryKV);};
	var groupKV = {:json_encode($groupKV);};
	var clientStatus = {:json_encode($clientStatus);};
	groupKV['0'] = '请选择';
	
	layui.use([ 'opTable', 'jquery', 'tool', 'laydate', 'laytpl', 'form'], function() {
		var $ = layui.jquery;
		var laytpl = layui.laytpl;
		var form = layui.form;
		var laydate = layui.laydate;
		
		laydate.render({
		    elem: '#create_date_range'
		    ,range: '~'
		    ,theme: 'molv'
		    ,mark: {'{:$today}':''}
	    	,change: function(value, date, endDate){
		    	$('#create_date_range').val(value);
            	$('#layui-laydate1').remove();//关闭面板
            }
		});
		laydate.render({
		    elem: '#over_date_range'
		    ,range: '~'
		    ,theme: 'molv'
		    ,mark: {'{:$today}':''}
		    ,change: function(value, date, endDate){
		    	$('#over_date_range').val(value);
            	$('#layui-laydate2').remove();//关闭面板
            }
		});
		laydate.render({
		    elem: '#caichuang_over_date_range'
		    ,range: '~'
		    ,theme: 'molv'
		    ,mark: {'{:$today}':''}
		    ,change: function(value, date, endDate){
		    	$('#caichuang_over_date_range').val(value);
            	$('#layui-laydate3').remove();//关闭面板
            }
		});
		var opTable = layui.opTable.render({
			elem : '#dataTable'
			,url : '{:url()}'
			,page: true
			,even: true
			,limit: 20
            ,limits: [5,10,20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
			,openVisible: false
			,toolbar: '#toolbar'
	        ,defaultToolbar: ['filter', 'exports', 'print']
			,cols : [[ 
				{field: 'defective_count', title:'尾完月份',templet:function(d){ if(d.caichuang_over_time>0){ 
					return"<span title="+layui.util.toDateString(d.tail_over_time * 1000,'yyyy-MM-dd HH:mm')+">"+layui.util.toDateString(d.tail_over_time * 1000,'yyyy-MM')+"</span>";
				}else{
						return '--';
				}}}
				,{field: 'client_ordernum', title:'工厂',templet:function(d){ return'<span class="copy-item" title="'+d.factory_id+'">'+factoryKV[d.factory_id]+'</span>'},width:96}
				,{field: 'sku', title:'下单件数',templet:function(d){ return'<span class="copy-item">'+d.order_count+'</span>';}}
				,{field: 'shicai_count', title:'裁床件数',width:95}
				,{field: 'sew_cut_count', title:'车间补裁片件数',width:70}
				,{field: 'jiaohuo_count', title:'车间成品数',width:90}
				,{field: 'field0', title:'车间差异(车间-裁床)',templet: function(d){return  d.jiaohuo_count-d.shicai_count;}}
				,{field: 'jiaohuo_tail_count', title:'尾部成品数'}
				,{field: 'custom_material_cost', title:'尾部差异(尾部-车间)',templet: function(d){return  d.jiaohuo_tail_count-d.jiaohuo_count;}}
				,{field: 'daohuo_count', title:'成品出货数'}
				,{field: 'store_count', title:'MES总入仓',width:80}
				,{field: 'cost', title:'米莫入库数',templet: function(d){return  d.available_checkin_count;}}
				,{field: 'defective_checkin_count', title:'次品数/没收数',width:60,templet: function(d){return  d.defective_checkin_count+'/'+d.mes_confiscate_count;}}
				,{field: 'can_checkout_stock', title:'总可出库数'}
				,{field: 'available_checkout_count', title:'实际出库数'}
				,{field: 'mes_checkin_diff_pre', title:'入仓差率(入仓/出货)'}
				,{field: 'available_pre', title:'正品率',sort: true}
				,{field: 'defective_pre', title:'次品率',sort: true}
				,{field: 'scrap_pre', title:'报废率(%)',sort: true,templet: function(d){return  d.scrap_pre;}}
				,{field: 'shicai_count_diff_pre', title:'入仓/裁剪差异'}
				,{field: 'shicai_count_diff_pre', title:'尾完订单/统计订单',templet:'#countOrderTpl'}
				,{field: 'field1', title:'操作',templet:'#buttonTpl'}
			]]
			,done:function(res) {
				$("#TotalPer").html('正品率：<strong>'+res.avaribleTotalPer+'%</strong>， 次品率：<strong>'+res.defectiveTotalPer+'%</strong>， 报废率：<strong>'+res.allSscrapPre+'%</strong>')
			}
		});	
		 //自定页
        window.searchdate = function(date) {
           	$("input[name=over_date_range]").val(date);
			var url='{:url()}?status='+status;
			$("#hisi-table-search").attr('action',url)
			$("#seacher").click();
           
            form.render();
		}


		// 尾部完成
		var layerDone = null;
		$(document).on('click','.tail-done',function(){
			var orderId = $(this).attr('data-id');
			var url = $(this).attr('data-url');
			var json = $(this).attr('data-json');
			var d = [];
			d['list'] = eval("(" + json+ ")");
			d['url'] = url;
			d['order_id'] = orderId;
			var content = laytpl($('#doneTpl').html()).render(d);
			layerDone = layer.open({
				type: 1
				,shade: 0
				,offset: '100px'
				,anim: parseInt(Math.random()*(6+1),10)
				,skin:'layui-layer-molv'
				,title:'后整数录入'
				,content: content
			});
		});

	});
</script>